//
//  TestViewController.m
//  123Mua_Modules
//
//  Created by duong nguyen on 11/3/12.
//  Copyright (c) 2012 uit. All rights reserved.
//

#import "TestViewController.h"

@interface TestViewController ()

@end

@implementation TestViewController
@synthesize isHiden,swipeGestureRecognizerDown,startTouchPosition,swipGestureRecognizerUp;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    isHiden=false;
    self.swipeGestureRecognizerDown=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeGestureRecognize:)];
    self.swipeGestureRecognizerDown.direction=UISwipeGestureRecognizerDirectionDown;
    self.swipGestureRecognizerUp=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeGestureRecognize:)];
    self.swipGestureRecognizerUp.direction=UISwipeGestureRecognizerDirectionUp;
    [self.view addGestureRecognizer:self.swipeGestureRecognizerDown];
    [self.view addGestureRecognizer:self.swipGestureRecognizerUp];
}

#pragma mark - GestureDelegate
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    
    return YES;
}

-(IBAction)handleSwipeGestureRecognize:(UISwipeGestureRecognizer *)recognizer{
    //CGPoint location=[self.swipeGetstureRecognizer locationInView:self.view];
    switch (recognizer.direction) {
        case UISwipeGestureRecognizerDirectionDown:
            [UIView animateWithDuration:0.5 delay:0.0 
                                options:UIViewAnimationOptionCurveEaseInOut 
                             animations:^{
                                 self.tabBarController.tabBar.center=CGPointMake(160, 505);
                             } completion:nil];

            break;
        case UISwipeGestureRecognizerDirectionUp:
            [UIView animateWithDuration:0.5 delay:0.0 
                                options:UIViewAnimationOptionCurveEaseInOut 
                             animations:^{
                                 self.tabBarController.tabBar.center=CGPointMake(160, 455);
                             } completion:nil];

            break;
        default:
            break;
    }
}
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)hideTabBar:(UIButton *)sender {
    if (isHiden) {
        [UIView animateWithDuration:1.0 delay:0.0 
                            options:UIViewAnimationOptionCurveEaseInOut 
                         animations:^{
                             self.tabBarController.tabBar.center=CGPointMake(160, 455);
                         } completion:nil];
        isHiden=false;
    }else {
        [UIView animateWithDuration:1.0 delay:0.0 
                            options:UIViewAnimationOptionCurveEaseInOut 
                         animations:^{
                             self.tabBarController.tabBar.center=CGPointMake(160, 505);
                         } completion:nil];
        isHiden=true;
    }
    
}
@end
